/*
 * @Author: zhangxiangsheng 1026583651@qq.com
 * @Date: 2024-06-24 13:41:38
 * @LastEditors: zhangxiangsheng 1026583651@qq.com
 * @LastEditTime: 2024-06-24 16:03:44
 * @FilePath: \appGly\pages\USearch\json.js
 * @Description:
 *
 * Copyright (c) 2024 by ${git_name_email}, All Rights Reserved.
 */
import store from "@/store/index";
import $t from '@/z/function/$t.js'
let defaultValue = uni.$z.defaultValue;
const utypstr = defaultValue.utype.map((e) => {
	return e.value;
});

let userstore = store.state.user;
const searchjson = [{
		label: $t("用户名"),
		value: "uUser"
	},
	{
		label: $t("联系人"),
		value: "uxm"
	},
	{
		label: $t("联系电话"),
		value: "utel"
	},
	{
		label: $t("用户类型"),
		value: "sutype",
		type: "select",
		defaultValue: `utype in (${utypstr.toString()})`,
		option: [{
				label: $t("全部"),
				value: `utype in (${utypstr.toString()})`
			},
			...defaultValue.utype.map((e) => {
				return {
					label: e.label,
					value: `utype in (${e.value})`
				};
			}),
		],
	},
	{
		label: $t("所属站点"),
		value: "pcs",
		type: "pcs"
	},
];
const Uaddjson = [{
		value: "uUser",
		label: $t("用户名"),
		rules: [{
			required: true,
			message: $t("请输入用户名"),
			trigger: "blur",
		}, ],
	},
	function({
		formData
	}) {
		const r = [];
		r.push({
			value: "dma",
			label: $t("密码"),
			type: "password",
			rules: [{
					required: true,
					message: $t("请输入密码"),
					trigger: "blur",
				},
				{
					validator(_rule, value, callback) {
						if (value && !isPassword(value)) {
							callback(new Error($t("密码格式不正确")));
						} else {
							callback();
						}
					},
					message: $t("密码应为6位以上，且不能全为数字或字母"),
					trigger: ["blur"],
				},
				{
					message: $t("密码最少为6位"),
					trigger: "blur",
					validator(_rule, value, callback) {
						if (value.length < 6) {
							callback(new Error("error"));
						} else {
							callback();
						}
					},
				},
			],
		});

		function qrdma(value, callback) {
			if (formData.dma != value) {
				callback(new Error("error"));
			} else {
				callback();
			}
		}
		r.push({
			value: "qrdma",
			label: $t("确认密码"),
			type: "password",
			rules: [{
				required: true,
				message: $t("请再次输入密码"),
				trigger: "blur",
				validator(_rule, value, callback) {
					qrdma(value, callback);
				},
			}, ],
		});

		return r;
	},
	{
		value: "utype",
		label: $t("用户类型"),
		type: "select",
		option: [...defaultValue.utype],
		defaultValue: defaultValue.utype[0].value,
	},
	{
		value: "pcs",
		label: $t("所属站点"),
		type: "pcs",

		defaultValue: userstore.USearch.pcs,
	},
	function({
		formData,
		propsdata
	}) {
		const r = [{
			value: "udj",
			label: $t("用户等级"),
			type: "select",
			option: "udj",
			defaultValue: "1",
			if: {
				zhi: [{
					value: "utype",
					zhi: ["11", "12", "0", "7", "15"]
				}],
			},
		}, ];
		r[0].option = defaultValue.typeudjfn(formData, propsdata);
		console.log(formData, propsdata);
		console.log('option', r[0].option);
		if (r[0].option.length != 0) {
			r[0].defaultValue = r[0].option[0].value;
		}

		return r;
	},

	{
		value: "uxm",
		label: $t("联系人"),

		rules: [{
			required: true,
			message: $t("请填写联系人"),
			trigger: "blur",
		}, ],
	},
	{
		value: "utel",
		label: $t("电话号码"),

		rules: [{
			required: true,
			message: $t("请填写电话号码"),
			trigger: "blur",
			validator(_rule, value, callback) {
				if (!test.mobile(value)) {
					callback(new Error("error"));
				} else {
					callback();
				}
			},
		}, ],
	},
	function({
		formData
	}) {
		return formData.utel == "" ? [] : [{
			value: "yzm",
			label: $t("验证码"),
			type: "yzm",
			span: 24,
			rules: [{
				required: true,
				message: $t("请输入验证码"),
				trigger: "blur",
			}, ],
		}, ];
	},
	{
		value: "bz",
		label: $t("备注"),
	},
];
const Uedtjson = [{
		value: "uUser",
		label: $t("用户名"),
		rules: [{
			required: true,
			message: $t("请输入用户名"),
			trigger: "blur",
		}, ],
		attrs: {
			disabled: true
		},
	},

	{
		value: "utype",
		label: $t("用户类型"),
		type: "select",
		option: [...defaultValue.utype],
		defaultValue: defaultValue.utype[0].value,
	},
	{
		value: "pcs",
		label: $t("所属站点"),
		type: "pcs",

		defaultValue: userstore.USearch.pcs,
	},
	function({
		formData,
		propsdata
	}) {
		const r = [{
			value: "udj",
			label: $t("用户等级"),
			type: "select",
			option: "udj",
			defaultValue: "1",
			if: {
				zhi: [{
					value: "utype",
					zhi: ["11", "12", "0", "7", "15"]
				}],
			},
		}, ];
		r[0].option = defaultValue.typeudjfn(formData, propsdata);
		if (r[0].option.length != 0) {
			r[0].defaultValue = r[0].option[0].value;
		}

		return r;
	},

	{
		value: "uxm",
		label: $t("联系人"),
	},
	{
		value: "utel",
		label: $t("电话号码"),
	},
	function({
		formData,
		propsdata
	}) {
		return formData.utel == "" || formData.utel == propsdata.utel ? [] : [{
			value: "yzm",
			label: $t("验证码"),
			type: "yzm",
			span: 24,
			rules: [{
				required: true,
				message: $t("请输入验证码"),
				trigger: "blur",
			}, ],
		}, ];
	},
	{
		value: "bz",
		label: $t("备注"),
	},
];

const Udmaedt = [{
		label: $t("用户名"),
		value: "uUser",
		type: "button"
	},
	{
		label: $t("旧密码"),
		value: "olddma",
		type: "password",
		rules: [{
			required: true,
			message: $t("请输入旧密码"),
			trigger: "change",
		}, ],
	},

	function({
		formData
	}) {
		const r = [];
		r.push({
			value: "dma",
			label: $t("新密码"),
			type: "password",
			rules: [{
					required: true,
					message: $t("请输入密码"),
					trigger: "blur",
				},
				{
					validator(_rule, value, callback) {
						if (value && !isPassword(value)) {
							callback(new Error($t("密码格式不正确")));
						} else {
							callback();
						}
					},
					message: $t("密码应为6位以上，且不能全为数字或字母"),
					trigger: ["blur"],
				},
				{
					message: $t("密码最少为6位"),
					trigger: "blur",
					validator(_rule, value, callback) {
						if (value.length < 6) {
							callback(new Error("error"));
						} else {
							callback();
						}
					},
				},
			],
		});

		function qrdma(value, callback) {
			if (formData.dma != value) {
				callback(new Error("error"));
			} else {
				callback();
			}
		}
		r.push({
			value: "qrdma",
			label: $t("确认密码"),
			type: "password",
			rules: [{
				required: true,
				message: $t("请再次输入密码"),
				trigger: "blur",
				validator(_rule, value, callback) {
					qrdma(value, callback);
				},
			}, ],
		});

		return r;
	},
];
export default {
	searchjson,
	Uaddjson,
	Uedtjson,
	Udmaedt,
};